<?php
/**
 * Created by PhpStorm.
 * User: mazhangyi
 * Date: 2020/1/8
 * Time: 19:17
 */

namespace app\api\controller\v1;
use app\api\controller\v1\common\Common;
use app\api\controller\v1\ValidateCode\ValidateCode;

class Code
{
  public function CodeImg(){
      header("Content-Type:image/png");
      session_start();
      $_vc = new ValidateCode();
      $_vc->doimg();
      //将验证码写入到session中;
      $_SESSION['validate-code'] = md5(strtolower($_vc->getCode()));
  }
  public function checkCode(){
      session_start();
      //validateCode.php  用于验证验证码是否正确的接口
      if(isset($_GET['vcode'])){//判断是否已经传递过vcode参数
          $vcode = md5(strtolower($_GET['vcode']));
          if($vcode == $_SESSION['validate-code']){
              $arr= ['code'=>200,'msg'=>'验证码输入正确!'];
          }else{
              $arr= ['code'=>100,'msg'=>'验证码错误,请重新输入~'];
          }
      }else{
          $arr= ['code'=>0,'msg'=>'参数缺少~'];
      }
      //输出json
      $json = json_encode($arr,JSON_UNESCAPED_UNICODE);
      echo $json;
  }
}